﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using HttpClientStudy.Core.Utilities;

namespace HttpClientStudy.UnitTest.UtilitiesTest
{
    public class AppUtilityTest
    {
        private readonly ITestOutputHelper _output;
        public AppUtilityTest(ITestOutputHelper testOutput) 
        {
            _output = testOutput;
        }

        [Fact]
        public void ApplicationPaths_Test()
        {
            var dic = AppUtility.GetApplicationPaths();

            string message = string.Empty;
            foreach (var path in dic) 
            {
                 message += ($"{path.Key} : {path.Value.path}{Environment.NewLine}");
            }

            _output.WriteLine(message);
        }

        [Fact]
        public void RunWebApiExeFile_Test()
        {
            string message = string.Empty;

            string apiFile = Path.GetFullPath("../../../../Docs/Publish/HttpClientStudy.WebApp/HttpClientStudy.WebApp.exe", Environment.CurrentDirectory);

            _output.WriteLine($"文件：{apiFile}");

            message = AppUtility.RunWebApiExeFile(apiFile);
            _output.WriteLine(message);
        }

        [Fact]
        public void RunWebApiExeFile_StayWindow_Test()
        {
            string message = string.Empty;

            string apiFile = Path.GetFullPath("../../../../Docs/Publish/HttpClientStudy.WebApp/HttpClientStudy.WebApp.exe", Environment.CurrentDirectory);

            _output.WriteLine($"文件：{apiFile}");

            message = AppUtility.RunWebApiExeFile(apiFile,true, "--urls=http://localhost:8644");
            _output.WriteLine(message);
        }

        [Fact]
        public void Cmd_Test()
        {
            string message = string.Empty;
            message = AppUtility.RunCmd("netstat -ano");

            _output.WriteLine(message);
        }
    }
}
